package chainSimplification;

import dviz.visualAnnotation.AttachVO;
import dviz.visualAnnotation.ConstructMap;

@AttachVO("PlaneVO")
public class Plane {
	Vector3f coordinate;
	Vector3f currentSpeed;
	Path path;
	float speed;
	int nextWayPoint;

	@ConstructMap("main")
	public Plane() {
		coordinate = new Vector3f();
		speed = 1;
		nextWayPoint = 0;
		currentSpeed = new Vector3f();
	}

	public void followPath(Path newPath) {
		this.path = newPath;
		nextWayPoint = 0;
	}

	public void setSpeed(float speed) {
		this.speed = speed;
	}

	public void update(float fpt) {
		if (path != null && nextWayPoint < path.getVertices().size()) {
			Vector3f delta = path.getVertices().get(nextWayPoint).subtract(
					coordinate);
			if (delta.length() < FastMath.ZERO_TOLERANCE) {
				nextWayPoint++;
				return;
			}
			Vector3f direction = delta.normalize();
			currentSpeed.set(direction);
			float length = delta.length();
			if (length < speed * fpt) {
				nextWayPoint++;
			}
			coordinate.addLocal(direction.mult(speed * fpt));
		}
	}

}
